package com.supermap.dataservice.cloud.api.user;

import com.supermap.dataservice.util.MD5;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

/**
 * @author aqua
 * @desc
 * @date 2019年05月27 14:49
 * @email 1301584033@qq.com
 */
@Component
public class AppKeyFactory {

        /**
         * @description:随机获取key值
         * @return
         */
        public  static String guid() {
            UUID uuid = UUID.randomUUID();
            String key = uuid.toString();
            return key;
        }
        /**
         * 这是其中一个url的参数，是GUID的，全球唯一标志符
         * @param product
         * @return
         */
        public String getAppKey(String str) {
            String guid = AppKeyFactory.guid();
            String app_key =null;
            try {
                app_key=  MD5.encode(guid).toUpperCase();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            return app_key;
        }
        /**
         * 根据md5加密
         * @param product
         * @return
         */
        public String getAppScrect(String str,String appKey) {
            String mw = str + appKey ;
            String app_sign = null;// 得到以后还要用MD5加密。
            try {
                app_sign = MD5.encode(mw).toUpperCase();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            return app_sign;
        }

}


